package com.businessportal.web.controllers.admin;

import com.businessportal.web.dataaccess.entities.Event;
import com.businessportal.web.dataaccess.entities.Login;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashSet;

/**
 * Created by Vadim on 9/18/14.
 */
@WebServlet(urlPatterns = "/securepages/admin_portal.do")
public class AdminPageController  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        try {
            req.setCharacterEncoding("UTF-8");

            HttpSession session = req.getSession();
            Login user = (Login) session.getAttribute("user");

            req.setAttribute("role", user.getRole());
            req.setAttribute("addreses", user.getAddress());
            req.setAttribute("full_name", user.getFullName());
        }
        catch(Exception e){
            req.setAttribute("errors", e.getMessage());
            req.setAttribute("events", new HashSet<Event>());

            req.setAttribute("role", null);
            req.setAttribute("full_name", "");
        }

        getServletContext().getRequestDispatcher("/securepages/admin_portal.jsp").forward(req, resp);
    }
}
